<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>修改临时闭馆</title>
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../css/oksub.css">
	<script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">
		<div class="layui-form-item">
			<label class="layui-form-label">闭馆时间</label>
			<div class="layui-input-block">
                <div class="layui-input-inline">
                    <input type="text" class="layui-input start_time" placeholder="闭馆开始时间" name="start_time" autocomplete="off" lay-verify="required">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input end_time" placeholder="闭馆结束时间" name="end_time" autocomplete="off" lay-verify="required">
                </div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">备注</label>
			<div class="layui-input-block">
				<input type="text" name="memo" placeholder="备注" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script type="text/javascript">
	layui.use(["form", "okLayer", "okUtils", "okMock", "laydate"], function () {
		let $ = layui.jquery;
		let form = layui.form;
		let okMock = layui.okMock;
        let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		//关闭loading
		okLoading.close();

        //初始化时间选择器
        laydate.render({elem: ".start_time", type: "datetime"});
        laydate.render({elem: ".end_time", type: "datetime"});

		//获取url地址中的参数
        var id = okUtils.getUrlParams("id");
		//发送ajax请求获取详情
		okUtils.ajax(okMock.api.temporary_close.detail, "get", {id: id}).done(function (response) {
			if (response.code == HTTP_OK) {
				//将数据填充到表单中
				$('input[name="name"]').val(response.data.name);
				$('input[name="start_time"]').val(response.data.start_time);
				$('input[name="end_time"]').val(response.data.end_time);
				$('input[name="memo"]').val(response.data.memo);
				if (response.data.status == 3) {
					//如果该临时闭馆已经执行过了，那么闭馆时间不能被修改
					$('input[name="start_time"]').attr("disabled", true);
					$('input[name="end_time"]').attr("disabled", true);
				}
				form.render();
			} else {
				layer.msg(response.message, { icon: 2, time: 2000 });
			}
		}).fail(function (error) {});

		//表单提交
		form.on("submit(add)", function (data) {
			data.field.id = id;
			//发送ajax提交表单数据
			okUtils.ajax(okMock.api.temporary_close.update, "post", data.field).done(function (response) {
				if (response.code == HTTP_OK) {
                    okLayer.greenTickMsg(response.message, function () {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    });
                } else {
                    layer.msg(response.message, { icon: 2, time: 2000 });
                }
			}).fail(function (error) {});
			return false;
		});
		
	})
</script>
</body>
</html>
